<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

</body>
<script src="lib/Promise.js"></script>
<script>

  /**
   * 使用自定义的Promise, 来创建一个实例对象promise
   * 指定回调函数的参数为resolve和reject, 这两个参数不需要自己提供, 有Promise构造内部提供
   *
   * @type {Promise}
   */

  const p1 = Promise.resolve(2);
  const p99 = Promise.resolve(99);
  const p2 = Promise.resolve(Promise.resolve(3));
  const p3 = Promise.resolve(Promise.reject(4));
  // p1.then(value => {
  //   console.log('p1', value)
  // })
  //
  // p2.then(value => {
  //   console.log('p2', value)
  // })
  // p3.catch(value => {
  //   console.log('p3', value)
  // })

  const p4 = new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(5)
    }, 1000)
  })
  // const p4 = Promise.resolveDelay(5, 1000)

  const pAll = Promise.all([p4, 8888, p1, p2]);
  const pRace = Promise.race([p3, p99, p2, p4, p1,]);

  // pAll.then(values => {
  //   console.log('all onResolved', values)
  // }).catch((reason) => {
  //   console.log('all onRejected', reason)
  // })
  //
  // pRace.then(value => {
  //   console.log('race onResolved', value)
  // }).catch((reason) => {
  //   console.log('race onRejected', reason)
  // })

  const p6 = Promise.resolveDelay(66, 2000);
  const p7 = Promise.rejectDelay(77, 3000);

  p6.then(value => {
    console.log('p6', value)
  })
  p7.catch(reason => {
    console.log('p7', reason)
  })
</script>
</html>
